﻿using System;
using System.Windows;
using WinForm = System.Windows.Forms;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void Help()
        {
            string helpFilePath = Globals.installedPath;
            if (helpFilePath.EndsWith("\\") == false)
            {
                helpFilePath += "\\";
            }

            helpFilePath += "Help\\Help.chm";

            if (System.IO.File.Exists(helpFilePath) == false)
            {
                MessageBox.Show("未找到帮助文档，无法继续！",
                    Globals.appName, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            //System.Diagnostics.Process.Start(helpFilePath);
            if (Globals.selectedEditor == null ||
                Globals.selectedEditor.SelectedExpression == null)
            {
                WinForm.Help.ShowHelp(null, helpFilePath);
            }
            else
            {
                string htmlString = "";
                if (Globals.selectedEditor.SelectedExpression is Expressions.Grid)
                {
                    htmlString = "gridexpression.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.LogicGenuspecies ||
                   Globals.selectedEditor.SelectedExpression is Expressions.LogicCross ||
                   Globals.selectedEditor.SelectedExpression is Expressions.LogicContradiction)
                {
                    htmlString = "logicexpressions.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.MarkText)
                {
                    htmlString = "marktext.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Triangle)
                {
                    htmlString = "triangle.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Bracket)
                {
                    htmlString = "bracket.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText)
                {
                    htmlString = "basetext.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Expander)
                {
                    htmlString = "expander.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.PictureBox)
                {
                    htmlString = "picturebox.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Tree)
                {
                    htmlString = "tree.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.LeafPanel)
                {
                    htmlString = "leafPanel.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.GridPanel)
                {
                    htmlString = "gridSubPanel.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.SubPanel)
                {
                    htmlString = "subpanel.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Arrow)
                {
                    htmlString = "arrow.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Brace)
                {
                    htmlString = "brace.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.RichText)
                {
                    htmlString = "richText.htm";
                }
                else if (Globals.selectedEditor.SelectedExpression is Expressions.Row)
                {
                    htmlString = "row.htm";
                }

                try
                {
                    if (htmlString != "")
                    {
                        WinForm.Help.ShowHelp(null, helpFilePath,
                             WinForm.HelpNavigator.Topic, htmlString);
                    }
                    else
                    {
                        WinForm.Help.ShowHelp(null, helpFilePath);
                    }
                }
                catch (Exception ex)
                {
                    Dialogs.LunarMsgBox.MsgBoxShow(
                        Globals.appName,
                        "发生意外错误，不能顺利打开帮助文档！",
                        "异常信息如下：\r\n" + ex.Message,
                        ex.StackTrace, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
        }
    }
}
